package com.sc.VenusQueryBeta.presenter.home.tabs;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.home.tabs.GuiBInContract;
import com.sc.VenusQueryBeta.model.bean.home.VipListBean;
import com.sc.VenusQueryBeta.model.home.tabs.GuiBinModel;

import io.reactivex.functions.Consumer;

/**
 * Created by SC-02 on 2018/9/19.
 *贵宾厅presenter
 */

public class GuiBInPresenter extends GuiBInContract.GuiBInPresenter {

    public static GuiBInPresenter newInstance() {
        return new GuiBInPresenter();
    }

    @Override
    protected GuiBInContract.IGuiBInModel getModel() {
        return GuiBinModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadLatestList() {

    }

    @Override
    public void loadMoreList() {

    }

    @Override
    public void onItemClick(int position, Object item) {

    }

    @Override
    public void getVipListData(int type) {
        if (mIModel==null||mIView==null) {
            return;
        }
        mRxManager.register(mIModel.getVipList(type).subscribe(new Consumer<VipListBean>() {

            @Override
            public void accept(VipListBean vipListBean) throws Exception {
                if (mIView != null)
                    mIView.showVipListDataSuccess(vipListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("error8489="+throwable.getLocalizedMessage());
                if (mIView != null) {
//                    if (mIView.isVisiable())
                    mIView.showToast("Network error.");
                    mIView.showNetworkError();
                }
            }
        }));
    }

    @Override
    public void getVipListData1(int type) {
        if (mIModel==null||mIView==null) {
            return;
        }
        mRxManager.register(mIModel.getVipList(type).subscribe(new Consumer<VipListBean>() {

            @Override
            public void accept(VipListBean vipListBean) throws Exception {
                if (mIView != null)
                    mIView.showVipListDataSuccess1(vipListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("error58959="+throwable.getLocalizedMessage());
                if (mIView != null) {
//                    if (mIView.isVisiable())
                    mIView.showToast("Network error.");
                    mIView.showNetworkError();
                }
            }
        }));
    }
}
